//
//  UIWindow+extension.m
//  12期传智微博HJ
//
//  Created by mac on 15-2-3.
//  Copyright (c) 2015年 jun. All rights reserved.
//

#import "UIWindow+extension.h"
#import "HJNewfeatureViewController.h"
#import "HJWelcomViewController.h"

@implementation UIWindow (extension)
/**
 *  选择根控制器
 */
- (void)chooseRootViewController{
    // 3.判断应该显示新特性还是欢迎界面
    // 3.1获取当前软件版本号
#warning 注意, 取出的版本号一定更要用字符串保存, 不要用浮点数 1.1.1
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    
    // 3.2获取沙盒中存储的软件版本号
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *sandboxVersion = [defaults objectForKey:@"CFBundleShortVersionString"];
    
    // 3.3比较两个软件版本号
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    if ([currentVersion compare:sandboxVersion] == NSOrderedDescending) {
        //新特性
        HJNewfeatureViewController *newfeature = [[HJNewfeatureViewController alloc]init];
        window.rootViewController = newfeature;
        //存储当前版本号
        [defaults setObject:currentVersion forKey:@"CFBundleShortVersionString"];
        [defaults synchronize];
    }else
    {
        //欢迎界面
        HJWelcomViewController *welcom = [[HJWelcomViewController alloc]init];
        window.rootViewController = welcom;
    }
}

@end
